package com.lonni.rpc.core.proxy.jdk;

import com.lonni.rpc.core.proxy.IProxy;
import com.lonni.rpc.core.register.model.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.lang.reflect.Proxy;

/**
 * JdkDynamicProxy：
 * jdk动态代理
 * @author: Lonni
 * @date: 2024/7/9 0009 14:58
 */
@Component
@Slf4j
public class JdkDynamicProxy implements IProxy,Serializable {


    /**
     *jdk 获取代理对象
     * @param tClass
     * @return
     */
    @Override
    public <T> T getProxy(Class<T> tClass, Service service) {
        Object proxyInstance = Proxy.newProxyInstance(tClass.getClassLoader(), new Class[]{tClass}, new RpcJdkInvocation<T>(tClass,service));
        return (T)proxyInstance;
    }
}



